import store from '@/store/'
import utils from '@/lib/utils'
import _config from '@/constant/config'

const middlewareSuperagent = function(){
  // if(typeof callback !== 'function') {
  //   throw new Error('You must provide correct callback function, for middleware to work properly');
  // }
  return function(req){
      //  req.url = _config.API_ROOT + req.url
    let token = store.state.user.token//若token为空则为游客模式
    if(token){
      req.header.session = token
    }
    req._callback_BodyParser = req.callback
    req.callback = function(err, res){
      if(res && res.status == 401){

      } else {
        req._callback_BodyParser(err, res)
      }
    }
  }
}

export default middlewareSuperagent
